
# build code in other layer
FROM rust:slim AS builder
LABEL maintainer="Abdusami@Kaayf <abdusami.dev@aliyun.com>" version="0.1.2" description="Naz Registry Center" logo="naz"
WORKDIR /usr/src/app
# set RsProxy as default cargo.io download source
RUN cat > ${CARGO_HOME}/config.toml << 'EOF'
[source.crates-io]
replace-with = 'rsproxy-sparse'
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
[net]
git-fetch-with-cli = true
EOF

# copy all source code from host to container
COPY . .
# build code
RUN cargo build --release

# create a layer to run compiled application from last layer
FROM debian:bookworm-slim
WORKDIR /opt/naz_registry
# copy compiled target programe only to run in this layer
COPY --from=builder /usr/src/app/target/release/naz_registry .
EXPOSE 8081

CMD ["./naz_registry"]
